package com.guofen.controller.sjq;

import com.guofen.pojo.SjqFlocculationCraftScene;
import com.guofen.pojo.SjqFlocculationProduceCheck;
import com.guofen.service.sjq.SjqFlocculationCraftSceneService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/flocculationCraftScene")
@Controller
@Api(tags = "SjqFlocculationCraftSceneController", description = "絮凝系统工艺现场记录表")
public class SjqFlocculationCraftSceneController {

    @Autowired
    private SjqFlocculationCraftSceneService sjqFlocculationCraftSceneService;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name = "xuNing_time", value = "时间", required = true) @RequestParam String xuNing_time,
                          @ApiParam(name = "drugPumpFlow1", value = "药泵流量计读数1", required = true) @RequestParam String drugPumpFlow1,
                          @ApiParam(name = "mudPumpFlow1", value = "泥泵流量计读数1", required = true) @RequestParam String mudPumpFlow1,
                          @ApiParam(name = "drugPumpFlow2", value = "药泵流量计读数2", required = true) @RequestParam String drugPumpFlow2,
                          @ApiParam(name = "mudPumpFlow2", value = "泥泵流量计读数2", required = true) @RequestParam String mudPumpFlow2,
                          @ApiParam(name = "drugPumpFlow3", value = "药泵流量计读数3", required = true) @RequestParam String drugPumpFlow3,
                          @ApiParam(name = "mudPumpFlow3", value = "泥泵流量计读数3", required = true) @RequestParam String mudPumpFlow3,
                          @ApiParam(name = "drugPumpFlow4", value = "药泵流量计读数4", required = true) @RequestParam String drugPumpFlow4,
                          @ApiParam(name = "mudPumpFlow4", value = "泥泵流量计读数4", required = true) @RequestParam String mudPumpFlow4,
                          @ApiParam(name = "tankLiquidLevel", value = "大调节池液位", required = true) @RequestParam String tankLiquidLevel,
                          @ApiParam(name = "flocculantNumber", value = "絮凝剂用量", required = true) @RequestParam String flocculantNumber,
                          @ApiParam(name = "ironNumber", value = "三氯化铁用量", required = true) @RequestParam String ironNumber,
                          @ApiParam(name = "recorder", value = "记录人", required = true) @RequestParam String recorder,
                          @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks){
        if (sjqFlocculationCraftSceneService.addForm(xuNing_time, drugPumpFlow1, mudPumpFlow1, drugPumpFlow2, mudPumpFlow2, drugPumpFlow3,
                mudPumpFlow3, drugPumpFlow4, mudPumpFlow4, tankLiquidLevel, flocculantNumber, ironNumber, recorder, remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/findForm", method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (sjqFlocculationCraftSceneService.findForm() != null)
            return ResultGenerator.genSuccessResult(sjqFlocculationCraftSceneService.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqFlocculationCraftSceneService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="xuningTime",value="时间",required=true) @RequestParam String xuningTime,
                         @ApiParam(name="drugpumpflow1",value="1# 药泵 流量计读数 （m³）",required=true) @RequestParam Double drugpumpflow1,
                         @ApiParam(name="mudpumpflow1",value="1# 药泵 流量计读数 （m³）",required=true) @RequestParam Double mudpumpflow1,
                         @ApiParam(name="drugpumpflow2",value="2# 药泵 流量计读数 （m³）",required=true) @RequestParam Double drugpumpflow2,
                         @ApiParam(name="mudpumpflow2",value="2# 药泵 流量计读数 （m³）",required=true) @RequestParam Double mudpumpflow2,
                         @ApiParam(name="drugpumpflow3",value="3# 药泵 流量计读数 （m³）",required=true) @RequestParam Double drugpumpflow3,
                         @ApiParam(name="mudpumpflow3",value="3# 药泵 流量计读数 （m³）",required=true) @RequestParam Double mudpumpflow3,
                         @ApiParam(name="drugpumpflow4",value="叠螺机 药泵 流量计读数 （m³）",required=true) @RequestParam Double drugpumpflow4,
                         @ApiParam(name="mudpumpflow4",value="叠螺机 药泵 流量计读数 （m³）",required=true) @RequestParam Double mudpumpflow4,
                         @ApiParam(name="tankliquidlevel",value="大调节池液位（m）",required=true) @RequestParam Double tankliquidlevel,
                         @ApiParam(name="flocculantnumber",value="絮凝剂用量（袋）",required=true) @RequestParam Double flocculantnumber,
                         @ApiParam(name="ironnumber",value="三氯化铁用量（桶）",required=true) @RequestParam Double ironnumber,
                         @ApiParam(name="recorder",value="记录人",required=true) @RequestParam String recorder,
                         @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks) {
        SjqFlocculationCraftScene record = new SjqFlocculationCraftScene();
        record.setId(id);
        record.setXuningTime(xuningTime);
        record.setDrugpumpflow1(drugpumpflow1);
        record.setMudpumpflow1(mudpumpflow1);
        record.setDrugpumpflow2(drugpumpflow2);
        record.setMudpumpflow2(mudpumpflow2);
        record.setDrugpumpflow3(drugpumpflow3);
        record.setMudpumpflow3(mudpumpflow3);
        record.setDrugpumpflow4(drugpumpflow4);
        record.setMudpumpflow4(mudpumpflow4);
        record.setTankliquidlevel(tankliquidlevel);
        record.setFlocculantnumber(flocculantnumber);
        record.setIronnumber(ironnumber);
        record.setRecorder(recorder);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqFlocculationCraftSceneService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqFlocculationCraftSceneService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqFlocculationCraftSceneService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
